import React from 'react'
import '../css/InputBox.css'
import eventEmitter from '../event';

class InputBox extends React.Component{
  constructor(props){
    super(props)
  }


  render(){
    return(
      <div className="send">
        <input type="text" ref='input'/>
        <button onClick={()=>{
          // console.log(this.refs.input.value);
          let value = this.refs.input.value
          if(value.length === 0){
            return alert('内容不能为空！')
          }
          let date = new Date();
          let dateStr = `${date.getFullYear()}年${date.getMonth()+1}月${date.getDate()}日${date.getHours()}时${date.getMinutes()}分`
          let message = {
            content : value,
            date : dateStr
          }

          eventEmitter.emit('sendmessage',message)


        }} >提交</button>
      </div>
    )
  }

}

export default InputBox